<template>
    <el-form ref="form" :model="form" label-width="80px">
        <div class="flex">
            <el-form-item label="选择模块" class="model">
                <el-select v-model="form.value" placeholder="请选择" @change="moduleIdFun">
                    <el-option v-for="item in modelsArr" :key="item.value" :label="item.assemblyName"
                        :value="item.assemblyId">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="选择工件" class="model">
                <el-select v-model="form.value1" placeholder="请选择" @change="modefun">
                    <el-option v-for="item in WorkpieceArr" :key="item.value" :label="item.workpieceName"
                        :value="item.workpieceId">
                    </el-option>
                </el-select>
            </el-form-item>
        </div>

        <el-form-item label="解决方案" class="model modelbox">
            <template>
                <div class="item" style="display: flex;" v-for="(v, i) in form.desc" :key="v.planId">
                    <div style="flex: 1;">

                        {{ v.description }}

                    </div>

                    <span>
                        <i v-if="v.admin" @click="playclick(v)" class="el-icon-circle-check"></i>
                        <i v-else class="el" @click="fileclick(v)"></i>
                    </span>
                </div>
            </template>
        </el-form-item>
        <el-form-item class="btn">
            <el-button type="primary" @click="onSubmit">添加</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import { saveExceptPaln, getByExcepId, getWorkPageByAssemblyId } from '@/api/fulitModelApi/index.js'
export default {
    props: ["options", "modelsArr", "except"],
    data() {
        return {
            planId: [],
            WorkpieceArr: [],
            form: {
                desc: [],
                value: '',
                value1: '',
            },
        }
    },
    mounted() {

    },
    methods: {
        moduleIdFun() {
            getWorkPageByAssemblyId({
                assemblyId: this.form.value,
            }).then(res => {
                if (res.code == 200) {
                    this.WorkpieceArr = res.data;
                    this.form.value1 = ""
                }
                if (res.code !== 200) {
                    this.$emit("errorTitle", res)
                }
            })
        },
        playclick(item) {
            item.admin = !item.admin

        },
        fileclick(item) {
            item.admin = !item.admin
        },

        modefun() {
            getByExcepId({
                workpieceId: this.form.value1
            }).then(res => {

                if (res.code !== 200) {
                    this.$emit("errorTitle", res)
                } else {
                    let list = []
                    res.data.forEach((v, i) => {
                        list.push({ ...res.data[i], admin: false })
                    })
                    this.form.desc = list
                }
            })
        },
        onSubmit() {
            this.form.desc.forEach((v, i) => {
                if (v.admin == true) {
                    this.planId.push(v.planId)
                }
            })
            saveExceptPaln({
                planIds: this.planId,
                exceptId: this.except.exceptId,
            }).then((res) => {
                this.WorkpieceArr = []
                this.form.desc = []
                this.form.value = ''
                this.form.value1 = ''
                this.$emit("reSetFun")
                if (res.code !== 200) {
                    this.$emit("errorTitle", res)
                }
            })


        }
    },
}
</script>
<style lang="less" scoped>
.el {
    display: inline-block;
    border: 1px solid #fff;
    background-color: transparent;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    cursor: pointer;

}

::-webkit-scrollbar {
    list-style: none;
}

.el-scrollbar {
    height: 100px !important;
}

.btn {
    margin-left: 18%;
    margin-top: 6%;
}

.el-select {
    width: 100px;
}


.item {
    background-color: #030c20;
    color: white;
    opacity: 1;
    width: 90%;
    color: #bee5fd;
    font-size: 14px;
    font-family: '思源黑';
    font-weight: 400;
    padding-left: 5px;
}

.el-input--suffix .el-input__inner {
    width: 100%;

    background-color: #030c20;
}

/deep/ .el-input__inner {
    background-color: #030c20 !important;
    color: white !important;
    border: 0px solid #5B9FC3 !important;
}

.el-select-dropdown__item.hover,
.el-select-dropdown__item:hover {
    background-color: #030c20;
    color: white;
    opacity: 1;
    border: 0px solid #5B9FC3;
}

.el-popper[x-placement^=bottom] {
    background-color: #000;
    color: white;
    opacity: 1;
    border: 0px solid #5B9FC3;
}

.el-form /deep/ .model {
    color: white;
    display: flex;
    flex-direction: row;
    align-items: center;
}

.el-inputmode {
    margin-left: 0px !important;
}

.el-form .modelbox {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.el-form .modelbox /deep/ .el-form-item__content {
    background: #031331;
    height: 70px;
    width: 90%;
    margin-left: 5% !important;
    border: .5px solid #273e6d;
    font-size: 16px;
    overflow: auto;

    div {
        width: 98%;
        height: 40px;
        line-height: 40px;
    }
}

.el-form .model /deep/ .el-form-item__label {
    width: 85px !important;
    margin-bottom: 3px;
    border: 0px solid #5B9FC3;
}

.flex {
    display: flex;
    justify-content: normal;
    height: 71px;
}

.el-color-picker__icon,
.el-input,
.el-textarea {
    height: 100%;
}

.el-form-item {
    margin-bottom: 0px;
}

.el-form-item {
    display: flex;
    flex-direction: column;
}

.el-input {
    width: 82%;
    margin-left: 31px;
}


.el-form-item /deep/ .el-form-item__content {
    margin-left: 0px !important;
    width: 60%;

    line-height: 15px !important;
}

.el-form-item /deep/ .el-form-item__label {
    width: 60% !important;
    text-align: left;
    color: white;
    margin-left: 20px;
    line-height: 40px;

}

.el-button--primary {
    width: 120px;
    height: 40px;
    background: #031231;
    opacity: 1;
    border: 1px solid #5B9FC3;
    margin: 10px 40%;
    cursor: pointer;
}
</style>